package com.zsguan.z.meixi;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.zsguan.z.zwidget4andr.viewpagerindicator.TabPageIndicator;

/**
 * Created by Administrator on 2015/9/16.
 * View pager indicator activity
 */
public class ZViewPagerIndicatorActivity extends FragmentActivity {

    private TabPageIndicator vpi_indicator;
    private ViewPager vpi_pager;

    private FragmentTextView[] fragments;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_viewpagerindicator);

        vpi_indicator = (TabPageIndicator) findViewById(R.id.vpi_indicator);
        vpi_pager = (ViewPager) findViewById(R.id.vpi_pager);

        fragments = new FragmentTextView[3];
        fragments[0] = new FragmentTextView("AAA");
        fragments[1] = new FragmentTextView("CCC");
        fragments[2] = new FragmentTextView("ZSG");

        setup();
    }

    private void setup() {
        vpi_pager.setAdapter(new VpiAdapter(getSupportFragmentManager()));
        vpi_indicator.setViewPager(vpi_pager);
    }

    class VpiAdapter extends FragmentPagerAdapter {

        public VpiAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return fragments[position].getName();
        }

        @Override
        public int getCount() {
            return fragments.length;
        }

        @Override
        public Fragment getItem(int position) {
            return fragments[position];
        }
    }
}
